package com.itheima.reggie.Impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.OrdersService;
import com.itheima.reggie.domain.Orders;
import com.itheima.reggie.domain.OrdersDetail;
import com.itheima.reggie.mapper.OrdersDetailMapper;
import com.itheima.reggie.mapper.OrdersMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;

    @Autowired
    private OrdersDetailMapper ordersDetailMapper;
    @Override
    public Page<Orders> findBy(Integer page, Integer pageSize, String number) {
        //分页
        Page<Orders> ordersPage = new Page<>(page,pageSize);
        // 准备封装查询条件
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(number),Orders::getNumber,number);
        Page<Orders> ordersPage1 = ordersMapper.selectPage(ordersPage, wrapper);





       /* List<Orders> records = ordersPage.getRecords();
        if (CollectionUtil.isNotEmpty(records)){
            for (Orders record : records) {
                OrdersDetail ordersDetail = ordersDetailMapper.selectById(record.getId());
                record.setNumber(ordersDetail.getName());
            }
        }*/

        //遍历
        return ordersPage1;
    }
}
